package com.ruoyi.youtian.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.youtian.domain.EquipmentCategory;
import com.ruoyi.youtian.service.IEquipmentCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备分类Controller
 *
 * @author ruoyi
 * @date 2022-09-07
 */
@RestController
@RequestMapping("/youtian/category")
public class EquipmentCategoryController extends BaseController
{
    @Autowired
    private IEquipmentCategoryService equipmentCategoryService;

    /**
     * 查询设备分类列表
     */
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(EquipmentCategory equipmentCategory)
    {
        startPage();
        List<EquipmentCategory> list = equipmentCategoryService.selectEquipmentCategoryList(equipmentCategory);
        return getDataTable(list);
    }

    /**
     * 导出设备分类列表
     */
    @Log(title = "设备分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentCategory equipmentCategory)
    {
        List<EquipmentCategory> list = equipmentCategoryService.selectEquipmentCategoryList(equipmentCategory);
        ExcelUtil<EquipmentCategory> util = new ExcelUtil<EquipmentCategory>(EquipmentCategory.class);
        util.exportExcel(response, list, "设备分类数据");
    }

    /**
     * 获取设备分类详细信息
     */
    @GetMapping(value = "/{equipmentCategoryId}")
    @ResponseBody
    public AjaxResult getInfo(@PathVariable("equipmentCategoryId") Long equipmentCategoryId)
    {
        return AjaxResult.success(equipmentCategoryService.selectEquipmentCategoryByEquipmentCategoryId(equipmentCategoryId));
    }

    /**
     * 新增设备分类
     */
    @Log(title = "设备分类", businessType = BusinessType.INSERT)
    @PostMapping
    @ResponseBody
    public AjaxResult add(@RequestBody EquipmentCategory equipmentCategory)
    {
        return toAjax(equipmentCategoryService.insertEquipmentCategory(equipmentCategory));
    }

    /**
     * 修改设备分类
     */
    @Log(title = "设备分类", businessType = BusinessType.UPDATE)
    @PutMapping
    @ResponseBody
    public AjaxResult edit(@RequestBody EquipmentCategory equipmentCategory)
    {
        return toAjax(equipmentCategoryService.updateEquipmentCategory(equipmentCategory));
    }

    /**
     * 删除设备分类
     */
    @Log(title = "设备分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{equipmentCategoryIds}")
    @ResponseBody
    public AjaxResult remove(@PathVariable Long[] equipmentCategoryIds)
    {
        return toAjax(equipmentCategoryService.deleteEquipmentCategoryByEquipmentCategoryIds(equipmentCategoryIds));
    }
}
